var path = require('path');
var webpack = require('webpack');
var node_modules = path.resolve(__dirname, 'node_modules');
var pathToReact = path.resolve(node_modules, 'react/index');

const devConfig = {
    devtool: 'eval-source-map',
    watch: true,
    entry: {
        "vendor": ['react', 'react-redux', 'react-dom'],
        "admin": "./static/src/js/admin/admin.js",
        "dingstore": "./static/src/js/store/dingstore.js",
        //"contacts": "./static/src/js/associator/contacts.js"
        //"settings": "./static/src/js/settings/dingstore.js",
        //"ordinary": "./static/src/js/ordinary/ordinary.js",
        "tasks": "./static/src/js/tasks/app.js",
        //"dashboard": "./static/src/js/dashboard/dingstore.js",
        //"workflows": "./static/src/js/workflows/dingstore.js",
        //"profile": "./static/src/js/profile/dingstore.js",
        //"not-found-error": "./static/src/js/errors/not-found-error.js",
    },
    output: {
        path: path.join(__dirname, 'static/dist/js/'),
        filename: "[name].js",
        chunkFilename: '[name].js',
        publicPath: '/dist/js/'
    },
    resolve: {
        extensions: ['', '.js', '.jsx']
    },
    resolve: {
        alias: {
            'react': pathToReact
        }
    },
    module: {
        loaders: [
            {
                test: /\.(js|jsx)$/,
                include: path.appSrc,
                exclude: /(node_modules|bower_components)/,
                loader: 'babel-loader',
                query: {
                    cacheDirectory: true,
                    presets: ['react', 'es2015'],
                    plugins: [["import", { libraryName: "antd", style: "css" }]]
                }
            },
            { test: /\.css$/, loader: 'style-loader!css-loader!postcss-loader' },
        ]
    },
    plugins: [
        // 提取公共代码
        new webpack.optimize.CommonsChunkPlugin({
            names: ['vendor'],
            filename: 'vendor.js'
        }),
        // 为组件分配ID
        new webpack.optimize.OccurrenceOrderPlugin(),
        // 热加载
        new webpack.HotModuleReplacementPlugin(),
        new webpack.NamedModulesPlugin(),
        new webpack.NoEmitOnErrorsPlugin(),
    ]

}


module.exports = devConfig;